package com.zzr.time.wheel;

public class Main {

    public static void main(String[] args) {

        System.out.println("start\t" + System.currentTimeMillis());

        addSameFirstLoop();
        System.out.println("stop\t" + System.currentTimeMillis());
//        //设置任务的延迟时间=10s
//        timer.addTask(new TimerTask(10000, () -> {
//            System.out.println("task\t" + System.currentTimeMillis());
//        }));
//
//        //设置任务的延迟时间=110s(超过了上层时间轮)
//        timer.addTask(new TimerTask(110_000, () -> {
//            System.out.println("task2\t" + System.currentTimeMillis());
//        }));

    }

    static void addSameFirstLoop() {
        //设置时间轮总长度=10s
        Timer timer = new Timer(1_000, 10);
        TimerTask timerTask1 = new TimerTask(9_000, () -> {
            System.out.println("task-1\t" + System.currentTimeMillis());
        });
        TimerTask timerTask2 = new TimerTask(9_000, () -> {
            System.out.println("task-2\t" + System.currentTimeMillis());
        });

        //添加两个相同的
        timer.addTask(timerTask1);
        timer.addTask(timerTask2);
    }
}
